package tests;

import common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;

import java.io.IOException;

public class PagesByNoLogin extends Utils {
    public static String loginUrl = "http://120.76.141.143:9090/login.html";
    public static String clientUrl = "http://120.76.141.143:9090/client.html";

    public PagesByNoLogin() {
        super("http://120.76.141.143:9090/login.html");
    }

    public void LoginPageByNoLogin() throws InterruptedException, IOException {
        driver.get(loginUrl);
        driver.navigate().refresh();

        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan111");
        driver.findElement(By.cssSelector("#password")).sendKeys("111111");
        driver.findElement(By.cssSelector("#submit")).click();
        Thread.sleep(1000);
        Alert alert = driver.switchTo().alert();
        String exceptText = alert.getText();
        assert exceptText.equals("登录失败！");
        alert.accept();
        getScreenShot(getClass().getName());
        driver.navigate().refresh();
    }

    public void ClientPageByNoLogin() throws InterruptedException, IOException {
        driver.get(clientUrl);
        Thread.sleep(1000);
        Alert alert = driver.switchTo().alert();
        alert.accept();
        String exceptTitle = "登录页面";
        String title = driver.getTitle();
        assert title.equals(exceptTitle);
        getScreenShot(getClass().getName());
        driver.navigate().refresh();
    }
}
